﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace WCSY.BLL
{
    public class fg_InitialBuMstManager
    {
        private readonly WCSY.DAL.fg_InitialBuMstService dal = new WCSY.DAL.fg_InitialBuMstService();
        public fg_InitialBuMstManager()
		{}
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string sysno)
        {
            return dal.Exists(sysno);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(WCSY.MODEL.fg_InitialBuMst MODEL)
        {
            return dal.Add(MODEL);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public string Update(WCSY.MODEL.fg_InitialBuMst MODEL)
        {
            return dal.Update(MODEL);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public string Delete(string sysno)
        {

            return dal.Delete(sysno);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string sysnolist)
        {
            return dal.DeleteList(sysnolist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WCSY.MODEL.fg_InitialBuMst GetMODEL(string sysno)
        {

            return dal.GetMODEL(sysno);
        }
         /// <summary>
        /// 初始预算数据录入
        /// </summary>
        /// <param name="deptno">部门代码</param>
        /// <param name="costs">费用项代码</param>
        /// <returns></returns>
        public DataTable getInitialList(string deptno, string costs)
        {
            return dal.getInitialList(deptno, costs);
        }
        /// <summary>
        /// 获取部门费用项预算值
        /// </summary>
        /// <param name="deptno">部门编码</param>
        /// <param name="costsno">费用项编码</param>
        /// <returns></returns>
        public DataTable getBuMoney(string deptno, string costsno)
        {
            return dal.getBuMoney(deptno, costsno);
        }
        /// <summary>
        /// 获取当前执行期间
        /// </summary>
        /// <returns></returns>
        public DataTable getNowBu()
        {
            return dal.getNowBu();
        }
         /// <summary>
        /// 获取数据库中已保存单据部门，费用项相同金额
        /// </summary>
        /// <param name="deptno"></param>
        /// <param name="costsno"></param>
        /// <returns></returns>
        public decimal getSumApplyMoney(string deptno, string costsno)
        {
            return dal.getSumApplyMoney(deptno, costsno);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<WCSY.MODEL.fg_InitialBuMst> GetMODELList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<WCSY.MODEL.fg_InitialBuMst> DataTableToList(DataTable dt)
        {
            List<WCSY.MODEL.fg_InitialBuMst> MODELList = new List<WCSY.MODEL.fg_InitialBuMst>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                WCSY.MODEL.fg_InitialBuMst MODEL;
                for (int n = 0; n < rowsCount; n++)
                {
                    MODEL = new WCSY.MODEL.fg_InitialBuMst();
                    if (dt.Rows[n]["sysno"] != null && dt.Rows[n]["sysno"].ToString() != "")
                    {
                        MODEL.sysno = dt.Rows[n]["sysno"].ToString();
                    }
                    if (dt.Rows[n]["period"] != null && dt.Rows[n]["period"].ToString() != "")
                    {
                        MODEL.period = dt.Rows[n]["period"].ToString();
                    }
                    if (dt.Rows[n]["uyear"] != null && dt.Rows[n]["uyear"].ToString() != "")
                    {
                        MODEL.uyear = dt.Rows[n]["uyear"].ToString();
                    }
                    if (dt.Rows[n]["fillpsn"] != null && dt.Rows[n]["fillpsn"].ToString() != "")
                    {
                        MODEL.fillpsn = dt.Rows[n]["fillpsn"].ToString();
                    }
                    if (dt.Rows[n]["fillDate"] != null && dt.Rows[n]["fillDate"].ToString() != "")
                    {
                        MODEL.fillDate = DateTime.Parse(dt.Rows[n]["fillDate"].ToString());
                    }
                    if (dt.Rows[n]["authorpsn"] != null && dt.Rows[n]["authorpsn"].ToString() != "")
                    {
                        MODEL.authorpsn = dt.Rows[n]["authorpsn"].ToString();
                    }
                    if (dt.Rows[n]["authorDate"] != null && dt.Rows[n]["authorDate"].ToString() != "")
                    {
                        MODEL.authorDate = DateTime.Parse(dt.Rows[n]["authorDate"].ToString());
                    }
                    MODELList.Add(MODEL);
                }
            }
            return MODELList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}
